Controller tuning exercise

Step 1

Load the model ControllerTuning.apros.

Run a sequence from SCL console that first sets the value of the set point (SP01#SP_VALUE) to 110, then waits 10 seconds and stops.

execute :: <Action,Proc> a -> Sequence a (Simantics/Sequences)

The sequence execute action is an instantious sequence that executes the operation action in the simulator.

setVar :: Serializable a => String -> a -> <Action> () (Simantics/Sequences)

Sets the value of a variable

wait :: Double -> Sequence () (Simantics/Sequences)

The sequence wait duration waits that duration seconds elapses from the current simulation time.

stop :: Sequence a (Simantics/Sequences)

The sequence stop stops all sequence threads, stopping the simulation completely.

Open the chart and examine the results.

Step 2

Put your sequence inside a function that takes the controller parameters PIC01#PI_GAIN and PIC01#PI_INTEGRATION_TIME as a parameter and sets them at the same time with the set point. It should also load the IC before simulation with command

loadInitialCondition (syncRead $ \_ -> fromResource $ relativeResource currentModel "/Initial%20Condition")

Step 3

Create a separate simulation thread that computes the last time the flow speed XA01#ANALOG_VALUE is within 1 from the set point value 110. Your function should return that value. The following functions are useful for that:

getVar :: Serializable a => String -> <Action> a (Simantics/Sequences)

Returns the current value of a variable

fork :: Sequence a -> Sequence () (Simantics/Sequences)

The sequence fork seq is an instantious sequence that creates a new sequence thread behaving like the sequence seq.

repeatForever :: Monad a => a b -> a c (Prelude)

Sequences the given monadic value infinitely:

repeatForever m = m >> m >> m >> ...

Step 4

Try the optimization routine

with function

f [x,y] = let dx=x-1 ; dy=y-2 in dx*dx + dy*dy

Step 5

Optimize the controller parameters using the objective function you created in step 3.